<?php

namespace Database\Seeders;

use App\Models\GoldCoin;
use Illuminate\Database\Seeder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;

class StormPrizeException extends Seeder
{
	public function run()
	{
		GoldCoin::query()
			->where('id', '>', '238263')
			->chunks(20, function (Collection $coins) {
				
				if ($coins->isEmpty()) return false;
				
				/**
				 * @var GoldCoin $coin
				 */
				foreach ($coins as $coin) {
					$data = ['gold_coin_id' => $coin->id];
					if ($coin->remark == 'gold_record_direct_prize') {
						account('gold_coin', $coin->user)->minusPrizeExceptional($coin->money, $data);
						Log::info("Coin: {$coin->id} gold_record_direct_prize returned");
					}
					if ($coin->remark == 'gold_record_team_prize') {
						account('gold_coin', $coin->user)->minusPrizeExceptional($coin->money, $data);
						Log::info("Coin: {$coin->id} gold_record_team_prize returned");
					}
				}
				
				return true;
				
			});
	}
}
